<!DOCTYPE html>
<html>
<head lang="en">
    <title>找攻略</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myStrategyComment.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script src="/js/checkLogin.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            var params = getParams();
            if (params.id) {
                //设置问题id,在隐藏域中,用于提交
                $("#answerForm input[name='questionId']").val(params.id);
                $.get(baseUrl + "/questions/" + params.id, function (data) {
                    //回显要回答的问题标题
                    $("#questionTitle").val(data.questionTitle);
                })
            }


            $("#answerBtn").click(function () {
                var json = JSON.parse(sessionStorage.getItem("user"));
                var currentUserId = json.id;
                if (json) {
                    $(".respondentId").val(currentUserId);
                }
                if ("" == $(".content").val() || $(".content").val() == null) {
                    $(document).dialog({
                        type: 'notice',
                        content: '<span class="info-text">内容不能为空</span>',
                        autoClose: 1000,
                        position: 'bottom'
                    });
                } else if ("" == $(".title").val() || $(".title").val() == null) {
                    $(document).dialog({
                        type: 'notice',
                        content: '<span class="info-text">内容不能为空</span>',
                        autoClose: 1000,
                        position: 'bottom'
                    });
                } else {
                    $("#answerForm").ajaxSubmit({
                        url:baseUrl + "answers/" + params.id,
                        success:function (data) {
                            window.location.href = "/answer.html?id=" + params.id;
                        }
                    })
                }
            });
        });
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>回答</span>
        </div>
        <div class="col"></div>
    </div>
</div>
<div class="comment">
    <div class="container answer">
        <form method="post" id="answerForm">
            <input type="hidden" name="questionId">
            <input type="hidden" name="respondent.id" value="0" class="respondentId">
            <p>问题</p>
            <input type="text" class="form-control" readonly id="questionTitle">
            <p>回答简介</p>
            <input name="answerTitle" class="form-control title" placeholder="请回答你对该问题的简述">
            <p>回答具体内容</p>
            <textarea name="answerContent" class="form-control content" rows="14"
                      placeholder="请回答你对该问题的具体内容"></textarea>
        </form>
    </div>
</div>
<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃回答</button>
    <button class="btn" id="answerBtn">提交回答</button>
</div>
</body>
</html>